// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import GameConfig from "../game/GameConfig";
import EventManager from "../manager/EventManager";

const {ccclass, property} = cc._decorator;

@ccclass
export default class UnitNode extends cc.Component {

    //@property(cc.Node)
    ui_tag: cc.Node = null;
    uid: string = "";
    UnitName: string = "";
    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.ui_tag = this.node.getChildByName("ui_tag");
        this.ui_tag.on("click", this.TagonClick, this);
    }

    TagonClick() {
        if (GameConfig.isUnitMove) {
            this.cancelToggle()
            return};
        this.ui_tag.getChildByName("ui_quan").active = true;
        EventManager.Inst.emit("UnitNode-TagonClick", this.uid);
    }

    cancelToggle(){
        this.ui_tag.getChildByName("ui_quan").active = false;
        //this.ui_tag.getComponent(cc.Toggle).uncheck();
    }


    setName(text){
        this.UnitName = text;
        this.node.getChildByName("unitName").getComponent(cc.Label).string = this.UnitName;
    }

    // update (dt) {}
}
